package com.yunkuhui.www.demo.configuration;

import com.yunkuhui.www.demo.conf.MongodbConf;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.mongodb.core.MongoTemplate;

@Configuration
public class MongodbConfiguration {

	private MongodbConf[] mongodbConf;

	@Autowired
	public MongodbConfiguration(@NotNull MongodbConf mongodbConf) {
		this.mongodbConf = mongodbConf.getMongodbConf();
	}

	@Primary
	@Bean(name = "testTemplate")
	public MongoTemplate testTemplate() {
		return mongodbConf[0].getMongoTemplate();
	}

	@Bean(name = "test1Template")
	public MongoTemplate test1Template() {
		return mongodbConf[1].getMongoTemplate();
	}
}
